import pidusage from "pidusage";
import type { NodeCpuType } from "~/utils";

/** 获取CPU、内存消耗等 */
export default defineEventHandler(async (event): Promise<NodeCpuType> => {
  const stats = await pidusage(process.pid);
  const { cpu, memory } = stats;
  return {
    memory: `内存占用：${(memory / 1024 / 1024 / 1024).toFixed(2)}GB`,
    cpu: `CPU占用：${cpu.toFixed(2)}%`,
  };
});
